package cn.aigoubuy.web.servelt;

import cn.aigoubuy.domain.Category;
import cn.aigoubuy.domain.Product;
import cn.aigoubuy.service.CategoryService;
import cn.aigoubuy.service.ProductService;
import cn.aigoubuy.service.impl.CategoryServiceImpl;
import cn.aigoubuy.service.impl.ProductServiceImpl;
import cn.aigoubuy.web.base.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/IndexServlet")
public class IndexServlet extends BaseServlet {
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        /*// 查询所有的分类
        CategoryService categoryService = new CategoryServiceImpl();
        List<Category> allCategory = categoryService.findAll();
        // 将查询结果存放到request域中
        request.setAttribute("allCategory",allCategory);*/

        ProductService productService = new ProductServiceImpl();
        // 1.1 查询热门商品
        List<Product> hotList = productService.findByHot();
        // 1.2 查询最新商品
        List<Product> newList = productService.findByNew();
        // 2.将查询结果存放
        request.setAttribute("hotList",hotList);
        request.setAttribute("newList",newList);

        //转发到真实的首页
        return "/jsp/index.jsp";
    }
}